-- 血猎者冈布奥

function initBloodHunterSlime(self, buildingInfo, dbase, pos)
    if type(dbase) ~= "table" or type(dbase["need_property"]) ~= "number" then
        -- 没要求，配置错误
        error("获取不到血猎者冈布奥物品配置！");
        return;
    end

    -- 获得血猎者冈布奥
    local function okFun()
        local bonusArgs = SlimeEventM.query(111, "bonus_args");
        local cost = bonusArgs["cost"][1];
        if cost[1] ~= 1 then
            -- 配置错误
            error("血猎者冈布奥扣除配置错误！");
            return;
        end

        -- 获取type
        local equipType = EquipM.query(cost[2], "type");
        -- 卸下血猎者斗篷
        if not DungeonActionM.go("do_unequip", 1, equipType) then
            -- 卸下失败
            return;
        end

        -- 尝试触发
        DungeonActionM.go("slime_event", pos, 111);

        -- 建筑消失
        playBuildingDisappear(self);
    end

    -- 获得血猎者碎片
    local function okFun2()
        local bonusArgs = SlimeEventM.query(112, "bonus_args");
        local cost = bonusArgs["cost"][1];
        if cost[1] ~= 1 then
            -- 配置错误
            error("血猎者冈布奥扣除配置错误！");
            return;
        end

        -- 获取type
        local equipType = EquipM.query(cost[2], "type");
        -- 卸下血猎者斗篷
        if not DungeonActionM.go("do_unequip", 1, equipType) then
            -- 卸下失败
            return;
        end

        -- 尝试触发
        DungeonActionM.go("slime_event", pos, 112);

        -- 建筑消失
        playBuildingDisappear(self);
    end

    local petId = SlimeEventM.query(111, "dbase")["pet_id"];
    -- 建筑图标
    local iconPath = getHeroIconPath(petId);
    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 格子失效了
                return;
            end

            if not DungeonBossM.canPickUpTarget() then
                -- 不能解救
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            if EquipM.isEquiped(dbase["need_property"]) then
                -- 装备有血猎者斗篷
                if HolyItemsM.isBaseLevelMax(dbase["need_property"])
                   and HolyItemsM.isExtraLevelMax(dbase["need_property"]) then
                    -- 已经满级
                    if PetM.getMyPet(petId) then
                        -- 有冈布奥
                        self:openBuildingView2(okFun2, nil, buildingInfo["view_text"],
                           buildingInfo["view_text2"], buildingInfo["dialog1"], iconPath, true);
                    else
                        -- 没有冈布奥
                        self:openBuildingView2(okFun, nil, buildingInfo["view_text"],
                           buildingInfo["view_text2"], buildingInfo["dialog1"], iconPath, true);
                    end
                else
                    -- 还未升级满
                    self:openBuildingView(nil, 0, getLocStr("blood_hunter_slime_dialog"), buildingInfo["view_text2"], nil, iconPath, nil, true);
                end
            else
                -- 没有斗篷
                self:openBuildingView(nil, 0, buildingInfo["dialog2"], buildingInfo["view_text2"], nil, iconPath, nil, true);
            end
            AudioM.playFx("slime_magician_app");
        end
    end

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
    self.icon:addTouchEventListener(onClicked);
    self.needAnimation =  true;
    self.icon:setPositionY(self.icon:getPositionY() + 15);

    -- 需要用监狱图标遮挡
    local prisonIcon = getLevelItemIconPath("prison");
    local prisonImg  = ccui.ImageView:create(prisonIcon);
    prisonImg:setTouchEnabled(false);
    prisonImg:setName("prison_icon");
    self.item:addChild(prisonImg);
end
